package org.jvm.weechat;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class LoginServer {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket =new ServerSocket(6666);
            System.out.println("登录服务器一起动，等待客户端的链接");
            while (true){
                Socket socket =serverSocket.accept();
                System.out.println("链接完毕");
                try {
                    socket.isClosed();
                    InputStream is= socket.getInputStream();
                    BufferedReader br =new BufferedReader(new InputStreamReader(is));
                    String message=br.readLine();
                    System.out.println("message:"+message);
                    //校验用户名密码
                    String[] values=message.split("-");
                    String username=values[0];
                    String password=values[1];
                    System.out.println(username+":"+password);
                    boolean state=new User().login(username,password);
                    OutputStream os=socket.getOutputStream();
                    PrintStream pw=new PrintStream(os);
                    pw.println(state+"");
                    pw.flush();
                }catch (Exception e){
                  e.printStackTrace();
                }

            }


        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
